package androidx.preference;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import androidx.preference.Preference;
import b.f.d.c.g;

public class ListPreference extends DialogPreference {
    private CharSequence[] W;
    private CharSequence[] X;
    private String Y;
    private String Z;
    private boolean a0;

    private static class a extends Preference.b {
        public static final Parcelable.Creator<a> CREATOR = new C0019a();

        /* renamed from: b  reason: collision with root package name */
        String f779b;

        /* renamed from: androidx.preference.ListPreference$a$a  reason: collision with other inner class name */
        static class C0019a implements Parcelable.Creator<a> {
            C0019a() {
            }

            /* renamed from: a */
            public a createFromParcel(Parcel parcel) {
                return new a(parcel);
            }

            /* renamed from: b */
            public a[] newArray(int i) {
                return new a[i];
            }
        }

        a(Parcel parcel) {
            super(parcel);
            this.f779b = parcel.readString();
        }

        a(Parcelable parcelable) {
            super(parcelable);
        }

        public void writeToParcel(Parcel parcel, int i) {
            super.writeToParcel(parcel, i);
            parcel.writeString(this.f779b);
        }
    }

    public static final class b implements Preference.g<ListPreference> {

        /* renamed from: a  reason: collision with root package name */
        private static b f780a;

        private b() {
        }

        public static b b() {
            if (f780a == null) {
                f780a = new b();
            }
            return f780a;
        }

        /* renamed from: c */
        public CharSequence a(ListPreference listPreference) {
            return TextUtils.isEmpty(listPreference.N0()) ? listPreference.i().getString(r.not_set) : listPreference.N0();
        }
    }

    public ListPreference(Context context) {
        this(context, (AttributeSet) null);
    }

    public ListPreference(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, g.a(context, m.dialogPreferenceStyle, 16842897));
    }

    public ListPreference(Context context, AttributeSet attributeSet, int i) {
        this(context, attributeSet, i, 0);
    }

    public ListPreference(Context context, AttributeSet attributeSet, int i, int i2) {
        super(context, attributeSet, i, i2);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, t.ListPreference, i, i2);
        this.W = g.q(obtainStyledAttributes, t.ListPreference_entries, t.ListPreference_android_entries);
        this.X = g.q(obtainStyledAttributes, t.ListPreference_entryValues, t.ListPreference_android_entryValues);
        int i3 = t.ListPreference_useSimpleSummaryProvider;
        if (g.b(obtainStyledAttributes, i3, i3, false)) {
            w0(b.b());
        }
        obtainStyledAttributes.recycle();
        TypedArray obtainStyledAttributes2 = context.obtainStyledAttributes(attributeSet, t.Preference, i, i2);
        this.Z = g.o(obtainStyledAttributes2, t.Preference_summary, t.Preference_android_summary);
        obtainStyledAttributes2.recycle();
    }

    private int Q0() {
        return L0(this.Y);
    }

    public int L0(String str) {
        CharSequence[] charSequenceArr;
        if (str == null || (charSequenceArr = this.X) == null) {
            return -1;
        }
        for (int length = charSequenceArr.length - 1; length >= 0; length--) {
            if (this.X[length].equals(str)) {
                return length;
            }
        }
        return -1;
    }

    public CharSequence[] M0() {
        return this.W;
    }

    public CharSequence N0() {
        CharSequence[] charSequenceArr;
        int Q0 = Q0();
        if (Q0 < 0 || (charSequenceArr = this.W) == null) {
            return null;
        }
        return charSequenceArr[Q0];
    }

    public CharSequence[] O0() {
        return this.X;
    }

    public String P0() {
        return this.Y;
    }

    public void R0(String str) {
        boolean z = !TextUtils.equals(this.Y, str);
        if (z || !this.a0) {
            this.Y = str;
            this.a0 = true;
            f0(str);
            if (z) {
                J();
            }
        }
    }

    /* access modifiers changed from: protected */
    public Object T(TypedArray typedArray, int i) {
        return typedArray.getString(i);
    }

    /* access modifiers changed from: protected */
    public void X(Parcelable parcelable) {
        if (parcelable == null || !parcelable.getClass().equals(a.class)) {
            super.X(parcelable);
            return;
        }
        a aVar = (a) parcelable;
        super.X(aVar.getSuperState());
        R0(aVar.f779b);
    }

    /* access modifiers changed from: protected */
    public Parcelable Y() {
        Parcelable Y2 = super.Y();
        if (G()) {
            return Y2;
        }
        a aVar = new a(Y2);
        aVar.f779b = P0();
        return aVar;
    }

    /* access modifiers changed from: protected */
    public void Z(Object obj) {
        R0(u((String) obj));
    }

    public void v0(CharSequence charSequence) {
        String charSequence2;
        super.v0(charSequence);
        if (charSequence == null && this.Z != null) {
            charSequence2 = null;
        } else if (charSequence != null && !charSequence.equals(this.Z)) {
            charSequence2 = charSequence.toString();
        } else {
            return;
        }
        this.Z = charSequence2;
    }

    public CharSequence z() {
        if (A() != null) {
            return A().a(this);
        }
        Object N0 = N0();
        CharSequence z = super.z();
        String str = this.Z;
        if (str == null) {
            return z;
        }
        Object[] objArr = new Object[1];
        if (N0 == null) {
            N0 = "";
        }
        objArr[0] = N0;
        String format = String.format(str, objArr);
        if (TextUtils.equals(format, z)) {
            return z;
        }
        Log.w("ListPreference", "Setting a summary with a String formatting marker is no longer supported. You should use a SummaryProvider instead.");
        return format;
    }
}
